/*
 * Copyright 2022 The Open Islands Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.openislands.oi.constant;

import java.util.HashMap;
import java.util.Map;

public enum TaskState implements StateInterface {
    READY(1000, "ready"),
    UP_FOR_RETRY(2000, "up_for_retry"),
    SCHEDULING_FAILED(3000, "scheduling_failed"),
    START_FAILED(4000, "start_failed"),
    SUBMITTED(5000, "submitted"),
    SUBMISSION_FAILED(6000, "submission_failed"),
    RUNTIME_ABORTED(7000, "runtime_aborted"),
    PENDING(8000, "pending"),
    ACTIVATING(9000, "activating"),
    ACTIVATION_FAILED(1100, "activation_failed"),
    RUNNING(1200, "running"),
    CANCELED(1300, "canceled"),
    TIMEOUT(1400, "timeout"),
    RUN_FAILED(1500, "run_failed"),
    SUCCESS(1600, "success"),
    ;

    private final static Map<Integer, TaskState> BY_CODE = new HashMap<>();
    static {
        for (TaskState e: values()
        ) {
            BY_CODE.put(e.getCode(), e);
        }
    }
    private final int code;
    private final String desc;

    TaskState(int code, String desc){
       this.code = code;
       this.desc = desc;
    }

    public static TaskState valueByCode(int code){
        return BY_CODE.get(code);
    }

    public int getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }
}
